User blog:TankAirTuna/Item generation
This is what blog posts are, right? So, item generation. Quite complex procedure that devolves into a few gosubs, vars and much headache. Here I will describe results of my continuing attemps to uncover mechanic behind all this. I don't understand what I'm doing about quarter of time, so there can be and probably will be mistakes. #deffunc itemcreate int prm_518, int prm_519, int prm_520, int prm_521, int prm_522 Here, prm_519 is ID of item (it'll get written into inv.s1 on offset 12, or var_99(3, id)), prm_520 is x coordinate, and prm_521 is y coordinate. prm_518 and prm_522... do something. In the start, nothing important happens before moving on to label_1897. label_1897 For most of equipment, if rnd(5000) is less than your luck, var_580, responsible for quality, will increase by 1, but no more than 5 (godly quality). After that, game will search for free space in array of items. If there's none, something will get deleted with message Too many item data! Some items in this area are destroyed. After that, free space will get cleared for new item. Then game'll assign X and Y coordinates, located at var_99(5, id) and var_99(6, id) (offsets 20 and 24). After that, game will go to label_0527, responsible for addition of base data (item type, price, material, description, charges...) depending on ID, and return back. If quality is 6 (Special), the name of item will get written in art.txt (for oracle spell). After, the game will assign amount of charges (for certain items), color of dye, type of skillbook, amount of gold, enchantment in cores of nefia, and other little fluff. From there we go on to label_1896: label_1896 Most items here have a chance to be cursed (1/13, with additional 1/4 chance to be doomed for... certain stuff? TODO: find out) or blessed (1/12 chance). Special items are always uncursed. After that, equipment gets a material! var_621(0, 0) = bronze (12), iron (34), mica (21), coral (33) var_621(0, 1) = metal (10), silver (25), glass (5), obsidian (20) var_621(0, 2) = steel (9), platinum (26), perl (22), mithril (7) var_621(0, 3) = chrome (30), crystal (11), emerald (23), adamantium (31) var_621(0, 4) = titanium (29), diamond (13), rubynus (15), ether (8) var_622(0, 0) = cloth (3), silk (2), paper (16), bone (18) var_622(0, 1) = leather (1), scale (4), glass (5), obsidian (20) var_622(0, 2) = chain (19), platinum (26), perl (22), mithril (7) var_622(0, 3) = zylon (27), gold (32), spirit cloth (14), dragon scale (24) var_622(0, 4) = dawn cloth (17), griffon scale (28), rubynus (15), ether (8) TODO: understand what this means, convert IDs into names. As you can see, this is array of materials. For each 15 levels of creature (or 10 of current object level, it depends on dungeon level or on something else, depending on source TODO: find out what) you essentialy get new 'tier' (or row) of equipment unlocked. Special rules for material kits: they get additional roll on 'quality' and in 1/3 chance pull material from first array. Furniture have equal chance to get material from either array. Some of the equipment will get materials mostly from first array, some - from second, with 1/10 chance of getting material from other array. (Note: items with material id 1000 take material mainly from first array, while items with id 1001 take mainly from second array. Lightsabers always generate ether, while rocks and stones are always metal) Another roll will determine tier (or row) from which you get the material. Depending on random, you'll get: Rarest materials from last column (5% chance) Materials from third column (20% chance) Materials from second column (30% chance) Materials from first column (45% chance) After all THAT, there's still flat 1/25 chance to get 'raw' material. Furniture with material cloth, paper, mica and silk have their material changed to wood automatically. Then, PV, DV, damage\hit rolls are modified, depending on material and quality (and random). Enchantments from material\base item (including static arts, they get enchantments now) are applied after. We then go on to *label_0308, where random enhantments are generated. Items with quality 2 or less immedietly return back. Blood rod Bloody Tears Ivy Spine whip Vice Staff Drake Rod Zwiebel Vital flayer Solar Cane Elemental Staff Staff of Insanity long staff staff These items have 5 independent rolls (1/10 chance) to recieve: Enchances your spells; Increases your Magic by x; Improves your Casting by x (if rolled, next rolls won't happen); Increases your Mana by x (if rolled, next roll won't happen); Improves your Magic Device by x; Now, items with quality lesser than 4 (thats 3, Great quality) recieve either rnd(rnd(5) + 1) + 1 random normal (rank 4-) enchantments, or random ego: Of silence: Improves Stealth, prevents teleport; Of resist blind: immunity to blindness; Of resist confusion: immunity to confusion; Of fire: resistance to fire and\or fire damage; Of cold: resistance to cold and\or cold damage Of lightning: resistance to lightning and\or lightning damage Of night: resistance to darkness and\or darkness damage Of illusion: resistance to mind and\or mind damage Of Poison: resistance to poison and\or posion damage Of hell: resistance to nether and\or netherdamage Of sound: resistance to sound and\or sound damage Of nerve: resistance to nerveand\or nerve damage Of chaos: resistance to chaos and\or chaos damage Of magic: resistance to magic and\or magic damage Of healing: Improves Healing Of resist paralysis: immunity to paralysis; Of resist fear: immunity to fear; Of resist sleep: immunity to sleep; Of defender: resistances to fire, cold and lightning Items with ego also have two separate chances (1/2 and 1/4) to recieve random enchantment. If item is of quality 5 (or 4 if rnd(10) rolls 0), game will give one enchantment of any rank, including rank 99. If it's a weapon, an additional rnd(100) roll will roll (sorry). If it rolls 0, the weapon becomes living, and returns immediately, not recieving any further enchantments. Now, random will determine amount of enchantments on item given. It's rnd(rnd(rnd(10) + 1) + 3) + 3 (3-14) for miracle quality or rnd(rnd(rnd(10) + 1) + 3) + 6 (6-17?) for godly quality If item is weapon and has more than 11 enchantments, it has 1/10 chance to recieve additional enchantment (up to rank 99), and become eternal force weapon. After that, normal random enchantments are added. For special items: 0-2 enchantments are added to preexisting, always up to rank 4. If the item is cursed or doomed, it'll recieve another random normal enchantment with 1.25 (or 1.5 if doomed) strength, then will attempt 1 + (1 if doomed) + rnd(2) times to add either 'weaken your resistance' (1.5 times strength) or 'weaken your skill' (2.5 times strength) enchantments with 1/3 chance each, or random -1 rank if both rolls don't succeed. flt This is good function. Doesn't actually do anything for generetion directly, but passes quality values to variables responsible. If none values are passed to function, generates them using object level of floor (DL+floor?), and base quality level 2, then passes them. calcfixlv int prm_495 This function is responsible for determining the quality level of item before generation. The var_574 (result) starts at prm_495, with default of 2. Most sources provide base level 2, but some sources: Salary (3, with chance of getting 4 (1/6 if you take the Apprentice Quartermaster feat, 2/6 if you improve it to Expert Quartermaster)) Chests (first item has 3) Treasure balls (3) Rare treasure balls (4) Bejeweled chest (3, with first item having 1/4 chance to have 4) Performance rewards (3 with varying chance to get 4) Quest rewards (starts at 2, with 1/2 chance to be 3, with additional 1/12 chance to be 4). (2 - good, 3 - great, 4 - miracle, just in case) I seem to stray slightly. Erm... So, the base level. Then, function performs 3 different rolls, they have: 1/35, 1/40, 1/45 chance to increase quality OR 2/35, 2/40, 2/45 chance to reduce it. Then, if quality is below 1, it changes to 1 and if above 5, becomes 5. randomenc() Done; this function forms an array of possible enchantments, then rolls one of them. The contents of this array (id's and weights, if I read it right) are formed depending on rank (no more than what is passed) and on types allowed. The types are in array below; because every single item has it, I truncated it, leaving only base weapon\armor types. If I forgot something, tell in comments. For example, enchantment 9, aka 'can be loaded with', can be recieved only by type 25000, or ammo (it also has absolutely crazy weight compared to others). Id's of enchantments with no limitations: 21, 45, 46, 47, 56, 59, 3, 6, 23, 1, 22, 25, 2, 24, 26, 27, 28, 48, 32, 33, 42, 8 (enchantment itself is free, but actual invoke is limited to weapons. Melee weapons can't get Draw Shadow, and ranged can't get Decapitation (randomly)). Table of enchantments. The item type needs to fit to one of types listed in table to be eligble to recieve enchantment. If type1 is 0, the enchantment is available to any item. Unfortunately, actual random lies within function exrand_rnd, which is located in exrand.dll. I couldn't find any documentation regarding it. randomencp() This function is responsible for generating random enchantment power. It is simply a few rolls, the first being rnd(rnd(500) + 1)) + 1, with additional rnd(51) with 1/5 chance (or always, if you activated secret treasure of Ehekatl). Max power thus is 550. Category:Blog posts